package com.hezuti.common.dao;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTransactionManager;

/**
 * 
 * @author xiaoyu.dou
 *
 */
@SuppressWarnings("serial")
public class RoutingHibernateTransactionManager extends HibernateTransactionManager {
	private RoutingSessionFactory routingSessionFactory;
	/**
	 * 
	 * @param routingSessionFactory
	 */
	public void setRoutingSessionFactory(RoutingSessionFactory routingSessionFactory) {
		this.routingSessionFactory = routingSessionFactory;
	}	
	/**
	 * 
	 */
	@Override
	public SessionFactory getSessionFactory() {
		if (!RoutingSynchronizeManager.isActive()) {
			throw new IllegalStateException("RoutingSynchronizeManager was not active when try getting sessionFactory.");
		}

		String key = RoutingSynchronizeManager.getResource();
		return routingSessionFactory.getSessionFactory(key);
	}
	/**
	 * 
	 */
	@Override
	public void afterPropertiesSet() {
		// suppress all checks, may be there's better way?
	}
}
